__author__ = 'el_even'

import pytest
from selenium import webdriver


def pytest_addoption(parser):
    """
    Adds parameters at moment of pytest starting
    """
    parser.addoption('--browser', action='store', default='firefox', help='browser type')
    parser.addoption('--base_url', action='store', default='http://ya.ru', help='base URL')

@pytest.fixture(scope='session')
def browser_type(request):
    return request.config.getoption('--browser')

@pytest.fixture(scope='session')
def base_url(request):
    return request.config.getoption('--base_url')

@pytest.fixture(scope='session')
def app(request, browser_type, base_url):
    if browser_type == 'firefox':
        driver = webdriver.Firefox()
    elif browser_type == 'chrome':
        driver = webdriver.Chrome()
    elif browser_type == 'opera':
        driver = webdriver.Opera()
    elif browser_type == 'ie':
        driver = webdriver.Ie()
    request.addfinalizer(driver.quit)
    return Application(driver, base_url)
